using DG.Tweening;
using UnityEngine;

public class BatteryAnim : MonoBehaviour
{
    private Sequence _sequence;
    public RectMesh[] _rectMesh;
    private int _count;
    
    void Start()
    {
        _count = _rectMesh.Length;
        var repeatTime = _count * 9 + 1;
        InvokeRepeating(nameof(DnAnim), 1, repeatTime);
    }

    private void DnAnim()
    {
        for (var i = 0; i < _count; i++)
        {
            _rectMesh[i].Length = 0;
        }
        for (var i = 0; i < _count; i++)
        {
            var mesh = _rectMesh[i];
            _sequence.Append(DOTween.To(() => mesh.Length, x => mesh.Length = x,
                2, 3).SetLoops(3).SetDelay(9 * i));
        }
    }
    
}
